<?php

/**
 * This is the model class for table "tbl_accounts".
 *
 * The followings are the available columns in table 'tbl_accounts':
 * @property string $id
 * @property string $user_id
 * @property integer $account_type_id
 * @property integer $period
 * @property string $cash
 * @property string $famous_point
 * @property integer $age_id
 * @property integer $country_id
 * @property string $city
 * @property string $personal_info
 * @property string $hobbies
 * @property string $member_since
 *
 * The followings are the available model relations:
 * @property AccountSetting[] $accountSettings
 * @property Users $user
 * @property AcountBookmarks[] $acountBookmarks
 * @property Blogs[] $blogs
 * @property Education[] $educations
 * @property Expertise[] $expertises
 * @property HistoryPurchase[] $historyPurchases
 */
class Account extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Account the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_accounts';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, account_type_id', 'required'),
			array('account_type_id, period, age_id, country_id', 'numerical', 'integerOnly'=>true),
			array('user_id, cash, famous_point', 'length', 'max'=>20),
			array('city', 'length', 'max'=>80),
			array('personal_info, hobbies, member_since', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, user_id, account_type_id, period, cash, famous_point, age_id, country_id, city, personal_info, hobbies, member_since', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'accountSettings' => array(self::HAS_MANY, 'AccountSetting', 'account_id'),
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
			'acountBookmarks' => array(self::HAS_MANY, 'AcountBookmarks', 'account_id'),
			'blogs' => array(self::HAS_MANY, 'Blogs', 'account_id'),
			'educations' => array(self::HAS_MANY, 'Education', 'account_id'),
			'expertises' => array(self::HAS_MANY, 'Expertise', 'account_id'),
			'historyPurchases' => array(self::HAS_MANY, 'HistoryPurchase', 'account_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'user_id' => 'User',
			'account_type_id' => 'Account Type',
			'period' => 'Period',
			'cash' => 'Cash',
			'famous_point' => 'Famous Point',
			'age_id' => 'Age',
			'country_id' => 'Country',
			'city' => 'City',
			'personal_info' => 'Personal Info',
			'hobbies' => 'Hobbies',
			'member_since' => 'Member Since',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('user_id',$this->user_id,true);
		$criteria->compare('account_type_id',$this->account_type_id);
		$criteria->compare('period',$this->period);
		$criteria->compare('cash',$this->cash,true);
		$criteria->compare('famous_point',$this->famous_point,true);
		$criteria->compare('age_id',$this->age_id);
		$criteria->compare('country_id',$this->country_id);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('personal_info',$this->personal_info,true);
		$criteria->compare('hobbies',$this->hobbies,true);
		$criteria->compare('member_since',$this->member_since,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}